#include <iostream>
#include <math.h>
#include <queue>
using namespace std;


struct point{
	int x,y,z;
	bool operator < (const point n)const{
		return z > n.z;
	}
};

double cac(point a,point b){ return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));}

int main(){
	int n;
	double ans=0;
	cin>>n;
	priority_queue<point> q;
	for(int i=0;i<n;i++){
		point l;
		cin>>l.x;
		cin>>l.y;
		cin>>l.z;
		q.push(l);
	}
	for(int i=0;i<n-1;i++){
		point l=q.top();
		q.pop();
		ans += cac(l,q.top());
	}
	printf("%0.3f",ans);
//	cout<<ans;
	return 0;
}
